const showMsgEle = document.getElementById("show-msg");
const inputMsgEle = document.getElementById("input-msg-ele");
const sendMsgBtn = document.getElementById("send-msg-btn");

// 接收iframe发过来的消息
window.addEventListener("message", function (e) {
  showMsgEle.value = e.data.msg;
});

// 给iframe发消息
sendMsgBtn.addEventListener("click", function () {
  window.frames[0].window.postMessage(
    {
      form: location.origin,
      msg: location.origin + "发送消息：" + inputMsgEle.value,
    },
    "*"
  );
});
